 {extend name="layout:base" /}{block name="content"}

 <?php
$global=isSupperManagerForSession();
 ?>
 <link rel="stylesheet" type="text/css" href="/static/My97DatePicker/skin/WdatePicker.css" />
     <script charset="utf-8" src="/static/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
  .yg_inp>input{margin-bottom: 10px;}
#zc_detail table{margin:10px;}
#zc_detail table tr td{
	border: 1px solid #ddd;
	height:40px;
	line-height:40px;
	padding-left:5px;
	padding-right:5px;
} 
.ordertable input {width:90%;}
.policeLable{padding:2px 4px;margin-left:4px;}
#taskDate .taskDateItem{
	width:100%;height:40px;line-height:40px;margin:4px 0px;
}
#taskDate .taskDateItem .taskDateItemLeft{width:10%;float:left;}
#taskDate .taskDateItem .taskDateItemRight1{width:70%;float:left;border:1px solid #139667;height: 42px;}
#taskDate .taskDateItem .taskDateItemRight2{width:20%;float:right;}
#taskDate .taskDateItem .opUsers img{width:22px;margin-left:5px;}

#taskDate .taskDateItem .itemUser{padding: 4px 6px;background:#139667;margin-left:4px;color:white;}
#taskDate .taskDateItem .clear{clear:both;width:0px;height:0px;overflow:hidden;}
#taskDate .taskDateItem .jia,#taskDate .taskDateItem .jian{font-size:30px;cursor:pointer;font-weight:800;margin-left:5px;}


  #attr .attrItem{width:80%;border:1px solid #ccc;margin-top:10px;font-size:12px;background-color:#efefef;}
  #attr .attrItem .attrItemName{width:98%;margin-top:10px;margin-left:auto;margin-right:auto;}
  #attr .line{width:98%;margin-left:auto;margin-right:auto;border-top:1px solid #ccc;height:1px;overflow:hidden;}
  #attr .attrItemValDiv{width:98%;margin-left:auto;margin-right:auto;}

  .fileItem{width:100px;float:left;height:100px;margin:10px;position: relative;border:1px solid #ccc;display: inline-block;background: white;border: 1px solid rgb(196, 196, 196);cursor: move;}
  .fileItem .productImg{max-width:100px;overflow:hidden;}
  .fileItem .productClose{color:red;font-size:20px;position:absolute;top:-10px;right:0px;cursor: pointer;}
  .drag-list {margin: 0 auto;}
  .drag-list > li {list-style: none;background: rgb(255, 255, 255);border: 1px solid rgb(196, 196, 196);margin: 5px 0;font-size: 24px;}
  .drag-list .title {display: inline-block;width: 130px;padding: 6px 6px 6px 12px;vertical-align: top;}
  .drag-list .drag-area {display: inline-block;background: rgb(158, 211, 179);width: 60px;height: 40px;vertical-align: top;float: right;cursor: move;}


</style>

<!--引入JS-->
<script type="text/javascript" src="/static/admin/js/ajaxfileupload.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/static/ueditor/lang/zh-cn/zh-cn.js"></script>


<section class="topBanners">
         <div class="icon"></div>
         <div class="topBannersNav">
             <span data-url="/admin/shop/lists" onclick="ContentLoadGo('/admin/shop/lists')">商品管理</span>
                >
             <span data-url="/admin/shop/editData"  onclick="ContentLoadGo('/admin/shop/editData?id=<?php echo $id; ?>')"  >编辑</span>
         </div>
      </section>
 <section id="zc_detail">
     <input type="hidden" value="<?php echo $id; ?>" id="editId" />
     <table class="ordertable" border="0" cellspacing="0" style="width:100%;" cellpadding="0">
         <tr>
             <td width="120"><div align="right">商品分类</div></td>
             <td class="tr_cons">
                 <select id="cls_id" class="select" name="data[cls_id]">
                     <option value="">--分类--</option>
                     <?php
                foreach($tyList as $key=>$val)
                     {
                     ?>
                     <option value="<?php echo $val['id']; ?>" <?php if($info['cls_id']==$val['id']){echo 'selected';} ?> ><?php echo $val['name']; ?></option>
                     <?php
                }
                ?>
                 </select>
             </td>
         </tr>
         <tr>
             <td width="120"><div align="right">商品名称</div></td>
             <td class="tr_cons">
                 <input type="text" name="data[name]" id="name" value="<?php echo $info['name']; ?>" placeholder="" class="textbox" style="padding:0px;" />
             </td>
         </tr>
         <tr>
             <td width="120"><div align="right">商品属性</div></td>
             <td class="tr_cons">
                 <div id="attr">
                     <?php
                        if(empty($goodAttribute))
                        {
                     ?>
                     <div class="attrItem">
                         <div class="attrItemName">
                             名称：<input type="text" name="attrName[]" class="textbox attrName" style="width:100px;" >
                             <i class="fa fa-plus-square fa-lg attrNameAdd"></i>
                         </div>
                         <div class="line"></div>
                         <div class="attrItemValDiv">
                             <div class="attrItemVal">&nbsp;&nbsp;&nbsp;&nbsp;值：<input type="text" name="attrVal[]" class="textbox attrVal" style="width:100px;" >
                                 <i class="fa fa-plus fa-lg attrValAdd"></i>
                             </div>
                         </div>
                     </div>
                     <?php
                       }
                       else
                       {
                        foreach($goodAttribute as $key=>$val)
                        {
                       ?>
                     <div class="attrItem">
                         <div class="attrItemName">
                             名称：<input type="text" name="attrName[]" value="<?php echo $val['name']?>" class="textbox attrName" style="width:100px;" >
                             <?php
                                if($key==0)
                                {
                             ?>
                             <i class="fa fa-plus-square fa-lg attrNameAdd"></i>
                             <?php
                                }else{
                                ?>
                             <i class="fa fa-minus-square fa-lg attrNameminus"></i>
                             <?php
                                }
                                ?>
                         </div>
                         <div class="line"></div>
                         <div class="attrItemValDiv">
                             <?php
                             if(empty($val['val']))
                             {
                             ?>
                             <div class="attrItemVal">&nbsp;&nbsp;&nbsp;&nbsp;值：<input type="text" name="attrVal[]" class="textbox attrVal" style="width:100px;" >
                                 <i class="fa fa-plus fa-lg attrValAdd"></i>
                             </div>
                             <?php
                             }else
                             {
                                foreach($val['val'] as $k=>$v)
                                {
                                    if($k==0)
                                    {
                                ?>
                             <div class="attrItemVal">&nbsp;&nbsp;&nbsp;&nbsp;值：<input type="text" name="attrVal[]" value="<?php echo $v?>" class="textbox attrVal" style="width:100px;" >
                                 <i class="fa fa-plus fa-lg attrValAdd"></i>
                             </div>
                                <?php
                                    }else
                                    {
                                    ?>
                             <div class="attrItemVal">&nbsp;&nbsp;&nbsp;&nbsp;值：<input type="text" name="attrVal[]" value="<?php echo $v?>" class="textbox attrVal" style="width:100px;" >
                                 <i class="fa fa-minus fa-lg attrValmius"></i>
                             </div>
                                    <?php
                                    }
                                }
                             }
                             ?>
                         </div>
                     </div>
                       <?php
                       }
                     }
                    ?>
                 </div>
             </td>
         </tr>




         <tr>
             <td width="120"><div align="right">商品原价</div></td>
             <td class="tr_cons">
                 <input type="text" name="data[money]" id="money" value="<?php echo $info['money']; ?>" placeholder="" class="textbox" style="padding:0px;" />
             </td>
         </tr>
         <tr>
             <td width="120"><div align="right">商品现价</div></td>
             <td class="tr_cons">
                 <input type="text" name="data[price]" id="price" value="<?php echo $info['price']; ?>" placeholder="" class="textbox" style="padding:0px;" />
             </td>
         </tr>

         <tr>
             <td width="120"><div align="right">库存</div></td>
             <td class="tr_cons">
                 <input type="text" name="data[number]" id="number" value="<?php echo $info['number']; ?>" placeholder="" class="textbox" style="padding:0px;" />
             </td>
         </tr>

         <tr>
             <td width="120"><div align="right">销量</div></td>
             <td class="tr_cons">
                 <input type="text" name="data[sale]" id="sale" value="<?php echo $info['sale']; ?>" placeholder="" class="textbox" style="padding:0px;" />
             </td>
         </tr>



         <tr>
             <td width="120"><div align="right">是否推荐</div></td>
             <td class="tr_cons">
                 <select name="data[hot]" id="hot" class="select">
                     <option value="0" <?php if($info['hot']=='0'){echo 'selected';} ?> >普通</option>
                     <option value="1" <?php if($info['hot']=='1'){echo 'selected';} ?> >推荐</option>
                 </select>
             </td>
         </tr>

         <tr>
             <td width="120"><div align="right">是否上架</div></td>
             <td class="tr_cons">
                 <select name="data[stats]" id="stats" class="select">
                     <option value="0" <?php if($info['stats']=='0'){echo 'selected';} ?> >上架</option>
                     <option value="1" <?php if($info['stats']=='1'){echo 'selected';} ?> >下架</option>
                 </select>
             </td>
         </tr>

         <tr>
             <td><div align="right">产品图</div></td>
             <td>
                 <form id="jvForm" name="jvForm" action="/api/face/updateImage1" method="post" enctype="multipart/form-data">

                     <a style="position:relative;display:inline-block;width:100px;height:30px;background:#EEE;border:1px solid #999;text-align:center;line-height:30px;"  href="javascript:void(0);" >上传文件
                         <input style="position:absolute;left:0;top:0;width:100px;height:30px;z-index:999;opacity:0;" onchange="uploadPic()" type="file" name="file" id="fileImage"   />
                     </a>
                     <input type="button" power="70000"  style="display:inline-block;width:100px;height:30px;background:#EEE;border:1px solid #999;text-align:center;line-height:30px;color:rgb(6, 193, 174);" value="裁剪上传" class="uImage"/>
                     <span style="color:red">提示：340*340px</span>
                     <div id="updateimg">
                         <?php
                          $fileArr = explode(",",$info['img']);
                          foreach($fileArr as $fk=>$fv)
                          {
                            if($fv){
                          ?>
                            <div class="fileItem" data-id="" data-pic="<?php echo $fv; ?>">
                                <div class="productClose">X</div>
                                <a href="<?php echo $fv; ?>" target="_blank"><img class="productImg" src="<?php echo $fv; ?>" /></a>
                            </div>
                          <?php
                            }
                          }
                         ?>
                     </div>
                 </form>

             </td>
         </tr>



         <tr>
             <td><div align="right">内容</div></td>
             <td colspan="7">
                 <script id="editor" type="text/plain" style="width:96%;height:500px;"><?php echo $info['content'] ?></script>
                 </td>
         </tr>
                 <tr>
                 <td width="120"><div align="right">排序</div></td>
                 <td class="tr_cons">
                     <input type="text" name="data[sorts]" id="sorts" value="<?php echo $info['sorts']; ?>" placeholder="" class="textbox" style="padding:0px;width:100px;" />越大越靠前
                     </td>
                     </tr>
      <tr>
       <td colspan="2" style="height:50px;text-align:center;">
			<input type="button" power="70000"  style="width:80px;margin-top:4px;margin-bottom:4px;padding:0px;" value="编辑" class="link_btn edit"/>
       </td>
     </tr>
   </table>
</section>
     
<script type="text/javascript">
var ue = UE.getEditor('editor').addListener("ready", function () {});
</script>
<script type="text/javascript">
function uploadPic()
{
 $.ajaxFileUpload({
        url: '/api/face/uploadImage1', //用于文件上传的服务器端请求地址
        secureuri: false, //是否需要安全协议，一般设置为false
        fileElementId: 'fileImage', //文件上传域的ID
        dataType: 'text/plain', //返回值类型 一般设置为json
        success: function (data, status) //服务器成功响应处理函数
        {

         if(data.err==0)
           {
             var tmpHtml ='<div class="fileItem" data-id="" data-pic="'+data.data.pic+'">' +
                 '<div class="productClose">X</div>' +
                 '<a href="'+data.data.pic+'" target="_blank"><img class="productImg" src="'+data.data.pic+'" /></a>' +
                 '</div>'
               $("#updateimg").append(tmpHtml);
               serportArrangeable();
           }
       },
       error: function (data, status, e)//服务器响应失败处理函数
       {
        alert(e);
       }
   })
   return false;
}
/**
 *
 * @returns 0表示检查通过 1检查不通过
 */
function checkGoodAttr()
{
    var flag=0;
    var attr=[];
    $("#attr .attrItem").each(function(k,v){
        var valItem ={name:"",val:[]};
        var name =$(v).find(".attrName:eq(0)").val();
        valItem.name=name;
        $(v).find(".attrVal").each(function(k1,v1){
            var tmpVal=$(v1).val();
            if(tmpVal!="")
            {
                valItem.val.push(tmpVal);
            }
        })
        if(valItem.val.length>0)
        {
            if(valItem.name.length<=0)
            {
                flag=1;
            }
        }
    });
    return flag;
}

function getGoodAttr()
{
    var attr=[];
    $("#attr .attrItem").each(function(k,v){
        var valItem ={name:"",val:[]};
        var name =$(v).find(".attrName:eq(0)").val();
        if(name!="") {
            valItem.name = name;
            $(v).find(".attrVal").each(function (k1, v1) {
                var tmpVal = $(v1).val();
                if (tmpVal != "") {
                    valItem.val.push(tmpVal);
                }
            })
            if(valItem.val.length>0) {
                attr.push(valItem);
            }
        }
    });
    return attr;
}
function uploadPicV()
{
   $("#uploadProgress").html("<img  src='/static/admin/images/loading.gif' style='width:50px;' />");
   $.ajaxFileUpload({
            url: '/api/face/uploadImage1', //用于文件上传的服务器端请求地址
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: 'fileVideo', //文件上传域的ID
            dataType: 'text/plain', //返回值类型 一般设置为json
            success: function (data, status) //服务器成功响应处理函数
            {

             if(data.err==0)
               {
                    var img='<a href="'+data.data.pic+'" target="_blank">'+data.data.pic+'</a>';
                    $("#updateimgV").html(img);
                    $("#uVideo").val(data.data.pic);
               }
              $("#uploadProgress").html("");
           },
           error: function (data, status, e)//服务器响应失败处理函数
           {
               $("#uploadProgress").html("异常");
           }
       })
    return false;
}
function myResearch(){
    var url="/admin/shop/editData";
    var id=$("#editId").val();
    ContentLoadGo(url+"?id="+id);
}
$(function(){
    var gnum=0;
    var lastObj;
    //商品属性相关
    $(".attrNameAdd").click(function () {
        var item='<div class="attrItem">\n' +
            '                    <div class="attrItemName">\n' +
            '                    名称：<input type="text" name="attrName[]" class="textbox attrName" style="width:100px;" >\n' +
            '                        <i class="fa fa-minus-square fa-lg attrNameminus"></i>\n' +
            '                    </div>\n' +
            '                    <div class="line"></div>\n' +
            '                    <div class="attrItemValDiv">\n' +
            '                            <div class="attrItemVal">&nbsp;&nbsp;&nbsp;&nbsp;值：<input type="text" name="attrVal[]" class="textbox attrVal" style="width:100px;" >\n' +
            '                                <i class="fa fa-plus fa-lg attrValAdd"></i>\n' +
            '                            </div>\n' +
            '                    </div>\n' +
            '                </div>';
        $("#attr").append(item);
    });
    $("body").on('click','.attrValAdd',function(){
        var item='<div class="attrItemVal">&nbsp;&nbsp;&nbsp;&nbsp;值：<input type="text" name="attrVal[]" class="textbox attrVal" style="width:100px;" >\n' +
            '                                <i class="fa fa-minus fa-lg attrValmius"></i>\n' +
            '                            </div>';
        $(this).parent().parent().append(item);
    });

    $("body").on('click','.attrValmius',function(){

        $(this).parent().remove();
    });
    $("body").on('click','.attrNameminus',function(){

        $(this).parent().parent().remove();
    });
//删除图标
    $("body").on('click','.productClose',function(){
        var that =this;
        cofirmsss_tishi(1,'您确定要删除该文件吗？',function(id) {
            $(that).parent().remove();
        });
    });


    //图片裁剪上传开始
    $(".uImage").click(function(){
        var that =this;
        var url="/admin/fileclip/uploadclip";
        var id="<?php echo $id;?>";//ID如果是编辑可以传入ID 如果是添加为0
        var dataid="uImage";//窗口隐藏后回显的id为该值的input框
        var msgshow="updateimg";//窗口隐藏后回显的id为该值的input框
        var width=710;//裁剪图片大小为该值
        var height=380;//裁剪图片大小为改值
        var param={
            id:id,
            msgshow:msgshow,
            width:width,
            height:height,
            dataid:dataid
        };
        MyContentLoad(url,param);
    });

    //图片裁剪上传结束


    //商品属性相关
    $(".colorAdd").click(function(){
        var item ='<div class="item">\n' +
            '                    <input type="text" name="color[]" class="textbox colorItem" style="width:100px;">\n' +
            '                </div>';
        $("#shopcolor").append(item);
    });

    $(".sizeAdd").click(function(){
        var item ='<div class="item">\n' +
            '                    <input type="text" name="size[]" class="textbox sizeItem" style="width:100px;">\n' +
            '                </div>';
        $("#shopsize").append(item);
    });
//编辑项
    $(".edit").unbind().bind("click",function(){
        var that =this;
        var url="/admin/shop/editData";
        var generaData=$("[name^='data']");
        var name=$("#name").val();
        var conts=UE.getEditor('editor').getContent();
        if(name=="") {
            ErrTiShi("商品名称不能够为空");return false;
        }
        //获取产品图
        var pic =[];
        $(".fileItem").each(function(i,v){
            var tmp = $(v).attr("data-pic");
            if(tmp)
            {
                pic.push(tmp);
            }
        });
        var picString = pic.join(",");
        //获取商品属性相关start
        if(checkGoodAttr()==1)
        {
            ErrTiShi("商品属性名称不能够为空");return false;
        }
        var attr =getGoodAttr();
        //获取商品属性相关end

        var id="<?php echo $id; ?>";
        var param={
            data:{
                img:picString
            },
            conts:conts,
            attr:JSON.stringify(attr),
            id:id,
            sys_opt:'addData'//后台判断编辑操作
        };
        getFormData(generaData,param.data);
        AjaxRequest(url,param,function(data){
           if(data.err==0) {
               SuccessTiShi("操作成功");
               myResearch();
           } else
           {
               ErrTiShi(data.msg);
           }
        });

   });
    //导航
    $(".topBannerItem").click(function(){
       var attArr = $(this).attr();
       goToSelfLink(attArr);
    });
});
</script>

 <script type="text/javascript" src="/static/js/drag-arrange.js"></script>
 <script type="text/javascript">
     function serportArrangeable(){
         $('.fileItem').arrangeable();
     }
     $(function() {
         serportArrangeable();
     });
 </script>
 {/block}